package com.jinlejia.bbs.ui.mine;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.jinlejia.bbs.R;
import com.jinlejia.bbs.bean.base.BBSUserBean;
import com.jinlejia.bbs.databinding.BbsActivityEditMineInfoBinding;
import com.jinlejia.bbs.help.CommonEvent;
import com.jinlejia.bbs.logic.mine.MyInfoLogic;
import com.jinlejia.bbs.ui.fun.BBSChooseTagActivity;

/**
 * 编辑资料页面
 */
public class BBSEditMineInfoActivity extends AppCompatActivity implements MyInfoLogic.LogicCallBack {
    private BbsActivityEditMineInfoBinding binding;
    private MyInfoLogic logic;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.bbs_activity_edit_mine_info);
        binding.setEvent(this);
        binding.setCommonEvent(CommonEvent.obtain());
        logic = new MyInfoLogic(this,this);
        initView();
    }

    private void initView() {
//        logic.execute();
    }

    public void back(View view){
        this.finish();
    }

    @Override
    protected void onResume() {
        logic.execute();
        super.onResume();
    }

    public void updateTag(View view){
        Intent intent = new Intent();
        if (tempUser!=null){
            intent.putExtra("tags",tempUser.getTags());
        }
        intent.putExtra("ignore",false);
        intent.putExtra("save",true);
        intent.setClass(this, BBSChooseTagActivity.class);
        startActivity(intent);
    }
    private BBSUserBean tempUser;
    @Override
    public void onResult(BBSUserBean user) {
        binding.setUser(user);
        Glide.with(this)
                .load(user.getUserAvatar())
                .dontAnimate()
                .fallback(R.mipmap.bbs_user_no_avatar)
                .into(new SimpleTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        binding.circleImageView.setImageDrawable(resource); //显示图片
                    }
                });
        tempUser = user;
    }
}
